package org.example.myleet.p728;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> result = new ArrayList<>(right - left);
        for (int num = left; num <= right; ++num) {
            if (isSelfDivisible(num)) {
                result.add(num);
            }
        }
        return result;
    }

    private boolean isSelfDivisible(int num) {
        int n = num, digit;
        while (num > 0) {
            if ((digit = num % 10) == 0 || n % digit != 0) {
                return false;
            }
            num /= 10;
        }
        return true;
    }
}
